package com.kidback.bbloc259.util;

import android.os.Build;
import android.provider.Settings;

import com.kidback.bbloc259.app.KidApplication;

/**
 * Created by meikai on 2020/07/01.
 */
public class DeviceUtils {

    /**
     * 判断系统定位服务是否开启
     */
    public static boolean isLocationEnabled() {
        int locationMode = 0;
        String locationProviders;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            try {
                locationMode = Settings.Secure.getInt(KidApplication.getInstance().getContentResolver(),
                        Settings.Secure.LOCATION_MODE);
            } catch (Settings.SettingNotFoundException e) {
                e.printStackTrace();
                return false;
            }
            return locationMode != Settings.Secure.LOCATION_MODE_OFF;
        } else {
            locationProviders = Settings.Secure.getString(KidApplication.getInstance().getContentResolver(),
                    Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
            return !StringUtils.isEmpty(locationProviders);
        }
    }

}
